// 328.奇偶链表

package Leetcode;

public class Solution328 {
    public ListNode oddEvenList(ListNode head) {
        ListNode odd = new ListNode();
        ListNode even = new ListNode();
        ListNode odd_pre = odd;
        ListNode even_pre = even;
        int count = 0;
        while (head != null) {
            ListNode next = head.next;
            if (count == 0) {
                head.next = odd.next;
                odd.next = head;
                odd = odd.next;
                count = 1;
            } else {
                head.next = even.next;
                even.next = head;
                even = even.next;
                count = 0;
            }
            head = next;
        }
        odd.next = even_pre.next;
        return odd_pre.next;
    }
}
